package com.wc.alorithm_luogu._前缀和与差分.马农;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/14 13:12
 * @description https://www.luogu.com.cn/problem/P2363
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 55;
    static int[][] a = new int[N][N];
    static int[][] s = new int[N][N];
    static int n;

    /**
     * 思路：二维前缀和
     * 枚举交点, 左上角 + 右上角
     * 右上角 + 左上角
     * 如果暴力的话是 n ^ 6 会超时
     * 那就用map计数上边的出现的数
     * 枚举下方就可以了
     */
    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                a[i][j] = sc.nextInt();
                s[i][j] += a[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
            }
        }
        long res = 0;
        // 枚举交点, 把交点归为上方的
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                int x = i, y = j;
                Map<Integer, Integer> map = new HashMap<>();
                for (int lx = 1; lx <= i; lx++) {
                    for (int ly = 1; ly <= j; ly++) {
                        int x1 = lx, y1 = ly, x2 = x, y2 = y;
                        int sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1];
                        map.put(sum, map.getOrDefault(sum, 0) + 1);
                    }
                }
                x = i + 1;
                y = j + 1;
                for (int rx = i + 1; rx <= n; rx++) {
                    for (int ry = j + 1; ry <= n; ry++) {
                        int x1 = x, y1 = y, x2 = rx, y2 = ry;
                        int sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1];
                        res += map.getOrDefault(sum, 0);
                    }
                }
                map = new HashMap<>();
                for (int rx = 1; rx <= i; rx++) {
                    for (int ry = j; ry <= n; ry++) {
                        int x1 = rx, y1 = j, x2 = i, y2 = ry;
                        int sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1];
                        map.put(sum, map.getOrDefault(sum, 0) + 1);
                    }
                }
                x = i + 1;
                y = j - 1;
                for (int lx = i + 1; lx <= n; lx++) {
                    for (int ly = 1; ly <= j - 1; ly++) {
                        int x1 = x, y1 = ly, x2 = lx, y2 = y;
                        int sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1];
                        res += map.getOrDefault(sum, 0);
                    }
                }
            }
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
